const { getSalespersons, getSalespersonsById, updateSalespersons, deleteSalespersons, addSalespersons, searchPersonal } = require('../dao/salespersonsDao')
module.exports.getSalespersons = async function (params) {
    if (params.value) {
        const data = await searchPersonal(params);
        return {
            message: '销售员数据搜索获取成功',
            status: 1,
            data
        }
    } else {
        const data = await getSalespersons(params);
        return {
            message: '销售员数据获取成功',
            status: 1,
            data
        }
    }
};


module.exports.getSalespersonsById = async function (params) {
    const data = await getSalespersonsById(params);
    if (data.length == 1) {
        return {
            message: '获取一个销售员个人信息成功',
            status: 1,
            data
        }
    } else {
        return {
            message: '获取销售员数据失败',
            status: 0,
            data
        }
    }
};
module.exports.updateSalespersons = async function (params) {
    const data = await updateSalespersons(params);
    if (data.nModified > 0) {
        return {
            message: '修改销售员信息成功',
            status: 1,
            data
        }
    } else {
        return {
            message: '修改销售员信息失败',
            status: 0,
            data
        }
    }
};
module.exports.deleteSalespersons = async function (params) {
    const data = await deleteSalespersons(params);
    console.log('删除的第二层', data);
    if (data.deletedCount > 0) {
        return {
            message: '删除销售员信息成功',
            status: 1,
            data
        }
    } else {
        return {
            message: '删除销售员信息失败',
            status: 0,
            data
        }
    }
};
module.exports.addSalespersons = async function (params) {
    const data = await addSalespersons(params);
    if (data) {
        return {
            message: '新增销售员成功',
            status: 1,
            data
        }
    } else {
        return {
            message: '新增销售员失败',
            status: 0,
            data
        }
    }
};
